package offer.singleLinkedList;

/**
 * Description：
 * Author: zhangc
 * Date：2017/7/21 11:28
 */
public class Node<T> {

    public T value;
    public Node next;

    public void setNext(Node next) {
        this.next = next;
    }

    public Node() {
    }

    public Node(T val) {
        this.value = val;
    }

    public void append(T value){
        if(this.value == null) {
            this.value = value;
            return;
        }
        Node head = this;
        while (head.next != null)
            head = head.next;
        head.next = new Node(value);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Node)) return false;

        Node<?> node = (Node<?>) o;

        if (!value.equals(node.value)) return false;
        return next != null ? next.equals(node.next) : node.next == null;
    }

    @Override
    public int hashCode() {
        int result = value.hashCode();
        result = 31 * result + (next != null ? next.hashCode() : 0);
        return result;
    }
}
